#include<iostream>
#include<math.h>
using namespace std;

int main(){
    int n,m,arr1[100][100],arr2[100][100];
    double tmp;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>arr1[i][j]; 
        } 
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
        	if(i==0||i==n-1||j==0||j==m-1)    
                arr2[i][j]=arr1[i][j];
            else{
                tmp=round((arr1[i-1][j]+arr1[i+1][j]+
							arr1[i][j-1]+arr1[i][j+1]+
							arr1[i][j])/5.0);
                arr2[i][j]=tmp;	
			}

                
            cout<<arr2[i][j]<<" ";
        }
        cout<<endl;
    }
}
